package cn.com.spic.demo.controller;

import cn.com.spic.demo.api.*;
import cn.com.spic.demo.dto.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cpipec.demo.spi.EOSServerRestClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 智能报告--公司对标提升工作月度报告
 */
@RestController
@RequestMapping("/smartReportItem")
public class SmartReportItemController {
    @Autowired
    private ActionProjectService actionProjectService;
    @Autowired
    private ProgressReportService progressReportService;
    @Autowired
    private EmployeeService employeeService;
    @Autowired
    private EOSServerRestClient eosServerRestClient;
    @Value("${file.address}")
    private String fileAddress;
    @Autowired
    private SpecialProjectService specialProjectService;
    @Autowired
    private ReportService reportService;
    @Autowired
    private OrganizationService organizationService;
    /**
     * 九大项
     * @param httpServletRequest
     * @return
     */
    @GetMapping(value = "/getNinePro" )
    public List<EchartDTO> getNinePro(HttpServletRequest httpServletRequest) throws ParseException {
        for(EchartDTO echartDTO:progressReportService.getNinePro()){
            System.out.println(echartDTO.getJdxid()+"========="+echartDTO.getJdx());
        }
        return progressReportService.getNinePro();
    }
    /**
     * 月度报告保存
     * @param request
     */
    @GetMapping("/saveReport")
    public String saveReport(HttpServletRequest request) throws ParseException {
       try{
           Calendar cal = Calendar.getInstance();
           String spicFirstDeptId = request.getParameter("spicFirstDeptId");
           String yyfx = request.getParameter("yyfx");
           String zfAndj = request.getParameter("zfAndjy");
           String jybgjcs = request.getParameter("jybgjcs");
           String status = request.getParameter("status");
           ReportDTO reportDTO=new ReportDTO();
           Map<String,String> map=new HashMap<>();
           EmployeeDTO employee = employeeService.getEmployeeById(getUserCode());
           String submitMonth = null;
           String submitYear = String.valueOf(cal.get(Calendar.YEAR));
           int month = cal.get(Calendar.MONTH);
           if(month<=9){
               submitMonth = "0"+month;
           }else{
               submitMonth = String.valueOf(month);
           }
           if(month==0){
               submitYear = String.valueOf(Integer.parseInt(submitYear)-1);
               submitMonth="12";
           }
           reportDTO.setType("2");
           reportDTO.setYyfx(yyfx);
           reportDTO.setZfAndjy(zfAndj);
           reportDTO.setJybgjcs(jybgjcs);
           reportDTO.setStatus(status);
           reportDTO.setDeptid(spicFirstDeptId==null?employee.getOrgCode():spicFirstDeptId);
           reportDTO.setCreateor(employee.getCode());
           reportDTO.setSubmitYear(submitYear);
           reportDTO.setSubmitMonth(submitMonth);
           map.put("submitYear",submitYear);
           map.put("submitMonth",submitMonth);
           map.put("deptid",spicFirstDeptId);
           map.put("type","2");
           ReportDTO reportDTO1=reportService.getReportByCondition(map);
           if(reportDTO1.getId()==null){
               reportService.insertReport(reportDTO);
           }else{
               reportService.updateReport(reportDTO);
           }

           return "保存成功";
       }catch (Exception e){
           e.printStackTrace();
       }
        return "保存失败，请重新保存！";
//        String actionId = request.getParameter("id");
//        progressReportService.insertProgress(progressReportDTOss);
    }
    /**
     * XX公司对标提升工作月度报告---原因分析，可编辑的信息
     * @param httpServletRequest
     * @return
     */
    @GetMapping(value = "/getReport" )
    public ReportDTO getReport(HttpServletRequest httpServletRequest) throws ParseException {
        Calendar cal = Calendar.getInstance();
        String spicFirstDeptId = httpServletRequest.getParameter("spicFirstDeptId");
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        String submitMonth = null;
        String submitYear = String.valueOf(cal.get(Calendar.YEAR));
        EmployeeDTO employee = employeeService.getEmployeeById(getUserCode());
        Map<String,String> map = new HashMap<>();
        int month = cal.get(Calendar.MONTH);
        if(month<=9){
            submitMonth = "0"+month;
        }else{
            submitMonth = String.valueOf(month);
        }
        if(month==0){
            submitYear = String.valueOf(Integer.parseInt(submitYear)-1);
            submitMonth="12";
        }
        map.put("submitYear",submitYear);
        map.put("submitMonth",submitMonth);
        map.put("type","2");
        if(spicFirstDeptId!=null&&!spicFirstDeptId.equals(employee.getOrgCode())){//如果非当前部门查看报告，填写的数据必须审核通过后才能看到
            map.put("status","3");
        }
        map.put("deptid",spicFirstDeptId==null?employee.getOrgCode():spicFirstDeptId);
        ReportDTO reportDTO=reportService.getReportByCondition(map);
        reportDTO.setSubmitYear(submitYear);
        reportDTO.setSubmitMonth(submitMonth);
        reportDTO.setCompname(organizationService.getOrgNameByCode(employee.getOrgCode()));
//        System.out.println(reportDTO.getCompname());
        return reportDTO;
    }



    /**
     * 计算时间差
     */
    private Long getDayNum(String day1,String day2) throws Exception {
        Date    a11 = new SimpleDateFormat("yyyy-MM-dd").parse(day1);
        Date    b11 = new SimpleDateFormat("yyyy-MM-dd").parse(day2);
        long dayNum = (a11.getTime()-b11.getTime())/(24*60*60*1000);
        return dayNum;
    }



    private static String subMonth(String date) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        Date dt = sdf.parse(date);

        Calendar rightNow = Calendar.getInstance();

        rightNow.setTime(dt);

        rightNow.add(Calendar.MONTH, -1);
        Date dt1 = rightNow.getTime();

        String reStr = sdf.format(dt1);

        return reStr;
    }
    /**
     * XX专项对标提升工作月度报告--累计进度报告
     * @param httpServletRequest
     * @return
     */
    @GetMapping(value = "/getActionByZx_ljjd" )
    public List<EchartDTO> getActionByZx_ljjd(HttpServletRequest httpServletRequest) throws ParseException {
        Calendar cal = Calendar.getInstance();
        String jdxid = httpServletRequest.getParameter("jdxid");
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        String submitMonth = null;
        String submitYear = String.valueOf(cal.get(Calendar.YEAR));
        EmployeeDTO employee = employeeService.getEmployeeById(getUserCode());
        Map<String,String> map = new HashMap<>();
        int month = cal.get(Calendar.MONTH);
        if(month<=9){
            submitMonth = "0"+month;
        }else{
            submitMonth = String.valueOf(month);
        }
        if(month==0){
            submitYear = String.valueOf(Integer.parseInt(submitYear)-1);
            submitMonth="12";
        }
        map.put("submitYear",submitYear);
        map.put("submitMonth",submitMonth);
        map.put("endtime",subMonth(new SimpleDateFormat("yyyy-MM-dd").format(new Date())));
        map.put("jdxid",jdxid);
        List<EchartDTO> echartDTOS = progressReportService.getActionByZx(map);//某个对标领域的120专项
        List<ActionProejctDTO> actionProejctDTOS=actionProjectService.getAllAction();//全部的行动项
        List<EchartDTO> list=new ArrayList<>();
        for(ActionProejctDTO actionProejctDTO:actionProejctDTOS){
            if(actionProejctDTO.getLevel().equals("1")&&actionProejctDTO.getSpecialId().equals(jdxid)){
                EchartDTO echartDTO=new EchartDTO();
                Double sjwc=0.0;
                Double jhwc=0.0;
                int count=0;
                for(EchartDTO echartDTO1:echartDTOS){
                    if(echartDTO1.getLevel().equals("3")){//如果等于3代表是二级单位
                        for(ActionProejctDTO actionProejctDTO1:actionProejctDTOS){
                            String parentid[]=echartDTO1.getActionid().split(",");
                            for(String str:parentid){
                                if(str.equals(actionProejctDTO1.getId())){
                                    String parentProjectId=actionProejctDTO1.getParentProjectId();
                                    if(parentProjectId.equals(actionProejctDTO.getId())){
                                        sjwc+=Double.parseDouble(echartDTO1.getSjwc());
                                        jhwc+=Double.parseDouble(echartDTO1.getJhwc());
                                        count++;
                                    }
                                }
                            }
                        }
                    }else if(echartDTO1.getLevel().equals("2")){
                        String parentid[]=echartDTO1.getActionid().split(",");
                        for(String str:parentid){
                            if(str.equals(actionProejctDTO.getId())){
                                sjwc+=Double.parseDouble(echartDTO1.getSjwc());
                                jhwc+=Double.parseDouble(echartDTO1.getJhwc());
                                count++;
                            }
                        }
                    }

                }
                echartDTO.setJdx(actionProejctDTO.getActionProName());
                echartDTO.setSjwc(sjwc/count+"");
                echartDTO.setJhwc(jhwc/count+"");
                list.add(echartDTO);
            }
        }
        for(EchartDTO echartDTO:list){
            System.out.println(echartDTO.getJdx()+"===="+echartDTO.getSjwc()+"====="+echartDTO.getJhwc());
        }
        return list;
    }
    /**
     * XX专项对标提升工作月度报告--月度进度报告
     * @param httpServletRequest
     * @return
     */
    @GetMapping(value = "/getActionByZx_ydjd" )
    public List<EchartDTO> getActionByZx_ydjd(HttpServletRequest httpServletRequest) throws ParseException {
        Calendar cal = Calendar.getInstance();
        String jdxid = httpServletRequest.getParameter("jdxid");
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        String submitMonth = null;
        String preSubmitMonth = null;
        String submitYear = String.valueOf(cal.get(Calendar.YEAR));
        String preSubmitYear = String.valueOf(cal.get(Calendar.YEAR));
        EmployeeDTO employee = employeeService.getEmployeeById(getUserCode());
        Map<String,String> map = new HashMap<>();
        Map<String,String> preMap = new HashMap<>();
        int month = cal.get(Calendar.MONTH);
        if(month<=9){
            submitMonth = "0"+month;
            preSubmitMonth = "0"+(month-1);
        }else{
            submitMonth = String.valueOf(month);
            preSubmitMonth = String.valueOf(month-1);
        }
        if(month==0){
            submitYear = String.valueOf(Integer.parseInt(submitYear)-1);
            submitMonth="12";
            preSubmitYear = String.valueOf(Integer.parseInt(submitYear)-1);
            preSubmitMonth="11";
        }
        if(month==1){
            preSubmitYear = String.valueOf(Integer.parseInt(submitYear)-1);
            preSubmitMonth="12";
        }
        map.put("submitYear",submitYear);
        map.put("submitMonth",submitMonth);
        map.put("jdxid",jdxid);
        map.put("endtime",subMonth(new SimpleDateFormat("yyyy-MM-dd").format(new Date())));
        preMap.put("submitYear",preSubmitYear);
        preMap.put("submitMonth",preSubmitMonth);
        preMap.put("jdxid",jdxid);
        preMap.put("endtime",subMonth(subMonth(new SimpleDateFormat("yyyy-MM-dd").format(new Date()))));
        List<EchartDTO> echartDTOS = progressReportService.getActionByZx(map);//某个对标领域的120专项
        List<EchartDTO> preEchartDTOS = progressReportService.getActionByZx(preMap);//填报月上一个月某个对标领域的120专项
        List<ActionProejctDTO> actionProejctDTOS=actionProjectService.getAllAction();//全部的行动项
        List<EchartDTO> list=new ArrayList<>();
        for(ActionProejctDTO actionProejctDTO:actionProejctDTOS){
            if(actionProejctDTO.getLevel().equals("1")&&actionProejctDTO.getSpecialId().equals(jdxid)){
                EchartDTO echartDTO=new EchartDTO();
                Double sjwc=0.0;
                Double jhwc=0.0;
                int count=0;
                for(EchartDTO echartDTO1:echartDTOS){
                    if(echartDTO1.getLevel().equals("3")){//如果等于3代表是二级单位
                        for(ActionProejctDTO actionProejctDTO1:actionProejctDTOS){
                            String parentid[]=echartDTO1.getActionid().split(",");
                            for(String str:parentid){
                                if(str.equals(actionProejctDTO1.getId())){
                                    String parentProjectId=actionProejctDTO1.getParentProjectId();
                                    if(parentProjectId.equals(actionProejctDTO.getId())){
                                        for(EchartDTO echartDTO2:preEchartDTOS){
                                            if(echartDTO2.getActionid().equals(echartDTO1.getActionid())){
                                                sjwc+=(Double.parseDouble(echartDTO1.getSjwc())-Double.parseDouble(echartDTO2.getSjwc()));
                                                jhwc+=(Double.parseDouble(echartDTO1.getJhwc())-Double.parseDouble(echartDTO2.getJhwc()));
                                                count++;
                                            }
                                        }

                                    }
                                }
                            }
                        }
                    }else if(echartDTO1.getLevel().equals("2")){
                        String parentid[]=echartDTO1.getActionid().split(",");
                        for(String str:parentid){
                            if(str.equals(actionProejctDTO.getId())){
                                sjwc+=Double.parseDouble(echartDTO1.getSjwc());
                                jhwc+=Double.parseDouble(echartDTO1.getJhwc());
                                count++;
                            }
                        }
                    }

                }
                DecimalFormat df = new DecimalFormat("0.00");
                echartDTO.setJdx(actionProejctDTO.getActionProName());
                echartDTO.setSjwc(df.format(sjwc/count)+"");
                echartDTO.setJhwc(df.format(jhwc/count)+"");
                list.add(echartDTO);
            }
        }
        for(EchartDTO echartDTO:list){
            System.out.println(echartDTO.getJdx()+"===="+echartDTO.getSjwc()+"====="+echartDTO.getJhwc());
        }
        return list;
    }
    private String getUserCode(){
        JSON json = eosServerRestClient.getCurrentUser();
        JSONObject object = JSONObject.parseObject(json.toJSONString());
        return object.getString("username");
    }
    /**
     * XX公司对标提升工作月度报告---逾期项目---详细信息
     * @param httpServletRequest
     * @return
     */
    @GetMapping(value = "/yuqiJdx_xiangxi" )
    public List<EchartDTO> yuqiJdx_xiangxi(HttpServletRequest httpServletRequest) throws ParseException {
        Calendar cal = Calendar.getInstance();
        String jdxid = httpServletRequest.getParameter("jdxid");
        String submitMonth = null;
        String submitYear = String.valueOf(cal.get(Calendar.YEAR));
        Map<String,String> map = new HashMap<>();
        int month = cal.get(Calendar.MONTH);
        if(month<=9){
            submitMonth = "0"+month;
        }else{
            submitMonth = String.valueOf(month);
        }
        if(month==0){
            submitYear = String.valueOf(Integer.parseInt(submitYear)-1);
            submitMonth="12";
        }
        map.put("submitYear",submitYear);
        map.put("submitMonth",submitMonth);
        map.put("jdxid",jdxid==null?"1":jdxid);
        map.put("endtime",subMonth(new SimpleDateFormat("yyyy-MM-dd").format(new Date())));
//        List<EchartDTO> echartDTOS = progressReportService.yuqiJdx_xiangxi(map);//全部项目数据
        List<EchartDTO> echartDTOS = progressReportService.getActionByZx(map);//某个对标领域的120专项
        List<ActionProejctDTO> actionProejctDTOS=actionProjectService.getAllAction();//全部的行动项
        List<EchartDTO> list=new ArrayList<>();
        DecimalFormat df=new DecimalFormat("00.00");
        for(ActionProejctDTO actionProejctDTO:actionProejctDTOS){
            if(actionProejctDTO.getLevel().equals("1")&&actionProejctDTO.getSpecialId().equals(jdxid)){
                EchartDTO echartDTO=new EchartDTO();
                Double sjwc=0.0;
                Double jhwc=0.0;
                int count=0;
                for(EchartDTO echartDTO1:echartDTOS){
                    if(echartDTO1.getLevel().equals("3")){//如果等于3代表是二级单位
                        for(ActionProejctDTO actionProejctDTO1:actionProejctDTOS){
                            String parentid[]=echartDTO1.getActionid().split(",");
                            for(String str:parentid){
                                if(str.equals(actionProejctDTO1.getId())){
                                    String parentProjectId=actionProejctDTO1.getParentProjectId();
                                    if(parentProjectId.equals(actionProejctDTO.getId())){
                                        sjwc+=Double.parseDouble(echartDTO1.getSjwc());
                                        jhwc+=Double.parseDouble(echartDTO1.getJhwc());
                                        count++;
                                    }
                                }
                            }
                        }
                    }else if(echartDTO1.getLevel().equals("2")){
                        String parentid[]=echartDTO1.getActionid().split(",");
                        for(String str:parentid){
                            if(str.equals(actionProejctDTO.getId())){
                                sjwc+=Double.parseDouble(echartDTO1.getSjwc());
                                jhwc+=Double.parseDouble(echartDTO1.getJhwc());
                                count++;
                            }
                        }
                    }

                }
               if(sjwc<jhwc){
                   echartDTO.setSjwc(df.format(sjwc/count*100)+"%");
                   echartDTO.setJhwc(df.format(jhwc/count*100)+"%");
                   echartDTO.setJtzxdbqdh(actionProejctDTO.getDef2());
                   echartDTO.setXdx(actionProejctDTO.getActionProName());
                   echartDTO.setEndtime(actionProejctDTO.getEndTime());
                   echartDTO.setQtdw(actionProejctDTO.getSpicFirstDeptId());
                   echartDTO.setPhdw(actionProejctDTO.getSpicSecDeptId());
                   echartDTO.setDbly(actionProejctDTO.getSpecialName());
                   list.add(echartDTO);
               }
            }
        }
//        DecimalFormat df=new DecimalFormat("0.00");
//        for(EchartDTO dto:echartDTOS){
//            dto.setSjwc(df.format(Double.parseDouble(dto.getSjwc())*100)+"%");
//            dto.setJhwc(df.format(Double.parseDouble(dto.getJhwc())*100)+"%");
//        }
        return list;
    }
    /**
     * XX公司对标提升工作月度报告---工作特点
     * @param httpServletRequest
     * @return
     */
    @GetMapping(value = "/groupReportMonth_gzjd" )
    public JSONObject groupReportMonth_gzjd(HttpServletRequest httpServletRequest) throws ParseException {
        Calendar cal = Calendar.getInstance();
        String jdxid = httpServletRequest.getParameter("jdxid");
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        String submitMonth = null;
        String submitYear = String.valueOf(cal.get(Calendar.YEAR));
        Map<String,String> map = new HashMap<>();
        Map<String,String> allmap = new HashMap<>();
        int month = cal.get(Calendar.MONTH);
        if(month<=9){
            submitMonth = "0"+month;
        }else{
            submitMonth = String.valueOf(month);
        }
        if(month==0){
            submitYear = String.valueOf(Integer.parseInt(submitYear)-1);
            submitMonth="12";
        }
        map.put("submitYear",submitYear);
        map.put("submitMonth",submitMonth);
        map.put("jdxid",jdxid==null?"1":jdxid);
        map.put("endtime",subMonth(new SimpleDateFormat("yyyy-MM-dd").format(new Date())));
        allmap.put("submitYear",submitYear);
        allmap.put("submitMonth",submitMonth);
        allmap.put("endtime",subMonth(new SimpleDateFormat("yyyy-MM-dd").format(new Date())));
        JSONObject jsonObject=new JSONObject();
        List<EchartDTO> echartDTOS1 = progressReportService.zxSjwcAndJhwc(map);
        List<EchartDTO> echartDTOS = progressReportService.getActionByZx(map);//某个对标领域的120专项
        List<ActionProejctDTO> actionProejctDTOS=actionProjectService.getAllAction();//全部的行动项
        List<EchartDTO> list=new ArrayList<>();
        for(ActionProejctDTO actionProejctDTO:actionProejctDTOS){
            if(actionProejctDTO.getLevel().equals("1")&&actionProejctDTO.getSpecialId().equals(jdxid)){
                EchartDTO echartDTO=new EchartDTO();
                Double sjwc=0.0;
                Double jhwc=0.0;
                int count=0;
                for(EchartDTO echartDTO1:echartDTOS){
                    if(echartDTO1.getLevel().equals("3")){//如果等于3代表是二级单位
                        for(ActionProejctDTO actionProejctDTO1:actionProejctDTOS){
                            String parentid[]=echartDTO1.getActionid().split(",");
                            for(String str:parentid){
                                if(str.equals(actionProejctDTO1.getId())){
                                    String parentProjectId=actionProejctDTO1.getParentProjectId();
                                    if(parentProjectId.equals(actionProejctDTO.getId())){
                                        sjwc+=Double.parseDouble(echartDTO1.getSjwc());
                                        jhwc+=Double.parseDouble(echartDTO1.getJhwc());
                                        count++;
                                    }
                                }
                            }
                        }
                    }else if(echartDTO1.getLevel().equals("2")){
                        String parentid[]=echartDTO1.getActionid().split(",");
                        for(String str:parentid){
                            if(str.equals(actionProejctDTO.getId())){
                                sjwc+=Double.parseDouble(echartDTO1.getSjwc());
                                jhwc+=Double.parseDouble(echartDTO1.getJhwc());
                                count++;
                            }
                        }
                    }

                }
                echartDTO.setJdx(actionProejctDTO.getActionProName());
                echartDTO.setSjwc(sjwc/count+"");
                echartDTO.setJhwc(jhwc/count+"");
                echartDTO.setXh(actionProejctDTO.getDef2());
                list.add(echartDTO);
            }
        }
        Double sjwc=0.0;
        Double jhwc=0.0;
        Integer yuqicount=0;
        String yuqixingdongx="";
        for(EchartDTO echartDTO:list){
            sjwc+=Double.parseDouble(echartDTO.getSjwc());
            jhwc+=Double.parseDouble(echartDTO.getJhwc());
            echartDTO.setJhwcl(sjwc/jhwc+"");
            if(Double.parseDouble(echartDTO.getSjwc())<Double.parseDouble(echartDTO.getJhwc())){
                yuqicount++;
                yuqixingdongx+=echartDTO.getJdx()+",";
            }
        }
        jsonObject.put("yuqiJdx",yuqicount);
        jsonObject.put("weiyuqiJdx",list.size()-yuqicount);
        jsonObject.put("yuqixingdongx",yuqixingdongx);
        Collections.sort(list, new Comparator<EchartDTO>()
        {
            public int compare(EchartDTO student1, EchartDTO student2)
            {
                return student2.getJhwcl().compareTo(student1.getJhwcl());
            }
        });
        System.out.println("==========================================");
        for(EchartDTO echartDTO:list){
            System.out.println(echartDTO.getJdx()+"===="+echartDTO.getSjwc()+"===="+echartDTO.getJhwcl());
        }
        DecimalFormat df = new DecimalFormat("0.00");
        for(int i=0;i<echartDTOS1.size();i++){
            if(echartDTOS1.get(i).getJdxid().equals(jdxid)){
                jsonObject.put("paiming",(i));
                jsonObject.put("jdx",echartDTOS1.get(i).getJdx());
                jsonObject.put("month",submitMonth);
                jsonObject.put("xdxCount",list.size());
                jsonObject.put("jhwc",df.format(jhwc/list.size()*100)+"%");
                jsonObject.put("sjwc",df.format(sjwc/list.size()*100)+"%");
                jsonObject.put("jhwcl",df.format(sjwc/jhwc*100)+"%");
                break;
            }

        }
                jsonObject.put("zhuanxqd_zk",list.get(0).getXh());
                jsonObject.put("zhuanxqdxx_zk",list.get(0).getJdx());
                jsonObject.put("zhuanxjhwcl_zk",df.format(Double.parseDouble(list.get(0).getJhwcl())*100)+"%");
                jsonObject.put("zhuanxqd_zm",list.get(list.size()-1).getXh());
                jsonObject.put("zhuanxqdxx_zm",list.get(list.size()-1).getJdx());
                jsonObject.put("zhuanxjhwcl_zm",df.format(Double.parseDouble(list.get(list.size()-1).getJhwcl())*100)+"%");
        return jsonObject;
    }
    public static void main(String [] args) throws ParseException {
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        String submityear="2021";
        String submitmonth="05";
        System.out.println(subMonth(submityear+"-"+submitmonth+"-30"));
    }
    /**

     * 获取两个日期相差的月数

     * @param d1 较大的日期

     * @param d2 较小的日期

     * @return 如果d1>d2返回 月数差 否则返回0

     */

    public static int getMonthDiff(Date d1, Date d2) {
        Calendar c1 = Calendar.getInstance();

        Calendar c2 = Calendar.getInstance();

        c1.setTime(d1);

        c2.setTime(d2);

        if(c1.getTimeInMillis() < c2.getTimeInMillis()) return 0;

        int year1 = c1.get(Calendar.YEAR);

        int year2 = c2.get(Calendar.YEAR);

        int month1 = c1.get(Calendar.MONTH);

        int month2 = c2.get(Calendar.MONTH);

        int day1 = c1.get(Calendar.DAY_OF_MONTH);

        int day2 = c2.get(Calendar.DAY_OF_MONTH);

// 获取年的差值 假设 d1 = 2015-8-16 d2 = 2011-9-30

        int yearInterval = year1 - year2;

// 如果 d1的 月-日 小于 d2的 月-日 那么 yearInterval-- 这样就得到了相差的年数

        if(month1 < month2 || month1 == month2 && day1 < day2) yearInterval --;

// 获取月数差值

        int monthInterval = (month1 + 12) - month2 ;

        if(day1 < day2) monthInterval --;

        monthInterval %= 12;

        return yearInterval * 12 + monthInterval;

    }

}

